﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Collections;
using System.Diagnostics;
using System.Drawing.Drawing2D;

namespace QuanLyRapChieuPhim
{
    public partial class frmDatVe : Form
    {
        public frmDatVe()
        {
            InitializeComponent();
        }
        private void frmDatVe_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < 100; i++ )
            {
                
                if (i %2 ==0)
                {
                    cbbRap.Items.Add("Bình " + i + i + i);
                }
                else
                {
                    cbbRap.Items.Add("Rạp " + i);
                }
            }
            pbDinhDangPhim.BringToFront();
            pbDinhDangPhim.BackColor = Color.Transparent;
            pbDinhDangPhim.Parent = pbPosert;
            //thay đổi hình ảnh theo mã định dạng phim
            pbDinhDangPhim.Image = changPicDinhDangPhim(true);

            pbPosert.Image = resizeImage(Image.FromFile("../../../icon/poster_icon.png"), new Size(pbPosert.Width,pbPosert.Height));
        }

        private void linkTrailer_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            ProcessStartInfo sInfo = new ProcessStartInfo(linkTrailer.Text);
            Process.Start(sInfo);
        }

        private Image changPicDinhDangPhim(bool status)
        {
            if (status)
            {
                return Image.FromFile("../../../icon/icon_2D.png");
            }
            return  Image.FromFile("../../../icon/icon_3D.png");
        }

        private Image resizeImage(Image imgToResize, Size size)
        {
            int sourceWidth = imgToResize.Width;
            int sourceHeight = imgToResize.Height;

            float nPercent = 0;
            float nPercentW = 0;
            float nPercentH = 0;

            nPercentW = ((float)size.Width / (float)sourceWidth);
            nPercentH = ((float)size.Height / (float)sourceHeight);

            if (nPercentH < nPercentW)
                nPercent = nPercentH;
            else
                nPercent = nPercentW;

            int destWidth = (int)(sourceWidth * nPercent);
            int destHeight = (int)(sourceHeight * nPercent);

            Bitmap b = new Bitmap(destWidth, destHeight);
            Graphics g = Graphics.FromImage((Image)b);
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;

            g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
            g.Dispose();

            return (Image)b;
        }

        private void nudSoLuongGhe_ValueChanged(object sender, EventArgs e)
        {
            //txtGiaVe
        }

        private void btnChonGhe_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Chon Ghe");
        }

        private void cbbRap_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
       

    }
}
